package zdc.util {
import away3d.tools.utils.TextureUtils;

import flash.display.BitmapData;
import flash.geom.Matrix;
import flash.geom.Point;

public class Away3DUtil {
    /**
     * 重调尺寸为2的倍数
     * @param bpd
     * @return
     */
    public static function powerResize(bpd:BitmapData):Point {
        var p:Point = new Point();
        p.x = TextureUtils.getBestPowerOf2(bpd.width);
        p.y = TextureUtils.getBestPowerOf2(bpd.height);
        return p;
    }


    public static function autoResizeBitmapData(bmData:BitmapData, smoothing:Boolean = true):BitmapData {
        if (TextureUtils.isBitmapDataValid(bmData))
            return bmData;

        var max:Number = Math.max(bmData.width, bmData.height);
        max = TextureUtils.getBestPowerOf2(max);
        var mat:Matrix = new Matrix();
        mat.scale(max / bmData.width, max / bmData.height);
        var bmd:BitmapData = new BitmapData(max, max);
        bmd.draw(bmData, mat, null, null, null, smoothing);
        return bmd;
    }
}
}